/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <unistd.h>
#include "sle_host_event_handler.h"
#include "sle_device_config.h"
#include "sle_hilog.h"
#include "sle_advanced_setting_manager.h"
namespace OHOS {
namespace NearLink {
namespace SleStandard {
SleHostEventHandler::SleHostEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner)
        : SleEventHandler(runner)
{
}

void SleHostEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
{
    SLE_ASSERT_AND_RETURN_LOG(event, "event null error!");
    SleHostEvent eventId = static_cast<SleHostEvent>(event->GetInnerEventId());
    SLE_LOGI("sle host event handler receive a message of %{public}d", eventId);
    switch (eventId) {
        case SleHostEvent::MSG_STATE_CHANGE:
            ProcessStateChange(event);
            break;
        default:
            SLE_LOGE("Unknown message received: id %{public}d", eventId);
            break;
    }
}

void SleHostEventHandler::ProcessStateChange(const AppExecFwk::InnerEvent::Pointer& event)
{
    SleDeviceState state;
    state = event->GetParam();
    AdvancedSettingManager::GetInstance()->ASProcessSleStateChange(state);

    bool result = true;
    SLE_LOGI("publish state change event result : %{public}d, state = %{public}d", result, state);
}
} // namespace SleStandard
} // namespace NearLink
} // namespace OHOS
